package com.feng.behavior
{
	import com.feng.data.UpgradeType;
	import com.feng.debug.logger;
	import com.feng.model.Player;
	import com.feng.ControllerCenter;

	/**
	 * 行为计算
	 * @author 风之守望者
	 * 2013-3-29
	 */
	public class BehaviorCompute
	{
		/**
		 * 获取攻击对象编号
		 */
		public function getAttackId():int
		{
			attackBehavior.attckDesireTable = [];
			var player:Player;
			for each (player in enemyList)
			{
				attackBehavior.attckDesireTable[player.id] = 0;
			}

			behaviorControler.ponderAttack();

			//寻找杀意值最大的敌人
			var targetId:int = enemyList[0].id;
			var maxAttckDesire:int = attackBehavior.attckDesireTable[enemyList[0].id];

			for each (player in enemyList)
			{
				if (maxAttckDesire < attackBehavior.attckDesireTable[player.id])
				{
					targetId = player.id;
					maxAttckDesire = attackBehavior.attckDesireTable[player.id];
				}
			}
			logger("攻击欲望 表," + attackBehavior.attckDesireTable.length + "," + JSON.stringify(attackBehavior.attckDesireTable));
			logger("我攻击" + targetId + "号");
			return targetId;
		}

		/**
		 * 获取加点编号
		 */
		public function getUpgradeId():int
		{
			//初始化数据
			defenseBehavior.defenseWillTable = [];
			defenseBehavior.defenseWillTable[UpgradeType.ADD_ATTACK] = 0;
			defenseBehavior.defenseWillTable[UpgradeType.ADD_DEFENSE] = 0;
			defenseBehavior.defenseWillTable[UpgradeType.ADD_SPEED] = 0;
			defenseBehavior.defenseWillTable[UpgradeType.ADD_ALL] = 0;

			behaviorControler.ponderDefense();

			//挑选出 防御意志 最强的选项
			var upgradeId:int = UpgradeType.ADD_ATTACK;
			if (defenseBehavior.defenseWillTable[upgradeId] < defenseBehavior.defenseWillTable[UpgradeType.ADD_DEFENSE])
			{
				upgradeId = UpgradeType.ADD_DEFENSE;
			}
			if (defenseBehavior.defenseWillTable[upgradeId] < defenseBehavior.defenseWillTable[UpgradeType.ADD_SPEED])
			{
				upgradeId = UpgradeType.ADD_SPEED;
			}
			if (defenseBehavior.defenseWillTable[upgradeId] < defenseBehavior.defenseWillTable[UpgradeType.ADD_ALL])
			{
				upgradeId = UpgradeType.ADD_ALL;
			}
			logger("防御意志 表," + defenseBehavior.defenseWillTable.length + "," + JSON.stringify(defenseBehavior.defenseWillTable));
			logger("我加成属性编号为：" + upgradeId);
			return upgradeId;
		}

		/*************************************************************/
		private var controllerCenter:ControllerCenter;

		public function BehaviorCompute(controllerCenter:ControllerCenter)
		{
			this.controllerCenter = controllerCenter;
		}

		private function get attackBehavior():AttackBehavior
		{
			return controllerCenter.attackBehavior;
		}

		private function get behaviorControler():BehaviorControler
		{
			return controllerCenter.behaviorControler;
		}

		private function get defenseBehavior():DefenseBehavior
		{
			return controllerCenter.defenseBehavior;
		}

		private function get enemyList():Vector.<Player>
		{
			return controllerCenter.stateData.enemyList;
		}

	}
}
